/**
 * @author Linrui
 * @since 2011-03-27
 * 用户的业务层封装类
 */
package com.qeado.user.service.implement;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qeado.user.dao.UserDao;
import com.qeado.user.model.User;
import com.qeado.user.service.UserService;

@Service
public class UserServiceImplement implements UserService {

	@Autowired
	private UserDao userDao;

	public boolean checkPassword(String id, String password) {
		if(userDao.checkPassword(id, password) == 1) {
			return true;
		} else {
			return false;			
		}
	}

	public boolean deleteUser(String userId) {
		return userDao.deleteUser(userId);
	}

	public boolean insertMessage(String message) {
		return userDao.insertMessage(message);
	}

	public String insertUser(User user) {
		if (user.getUserName() != null && !"".equals(user.getUserName())) {
			Object obj = userDao.queryByName(user.getUserName());
			if (obj != null) {
				return "该用户名已存在";
			} else {
				user.setId(UUID.randomUUID().toString());
				if( userDao.insertUser(user) )
					return "success";
				else
					return "visit_fail";
			}
		} else {
			return "用户名为空";
		}

	}

	public User queryById(String userId) {
		return userDao.queryById(userId);
	}

	public User queryByName(String userName) {
		return userDao.queryByName(userName);
	}

	public User queryByNameByPassword(String userName, String password) {
		return userDao.queryByNameByPassword(userName, password);
	}

	public boolean updateBelongColleage(String colleageId, String userId) {
		return userDao.updateBelongColleage(colleageId, userId);
	}

	public boolean updateBelongCompany(String companyId, String userId) {
		return userDao.updateBelongCompany(companyId, userId);
	}

	public boolean updatePassword(String ID, String password) {
		return userDao.updatePassword(ID, password);
	}

	public boolean updateUser(User user) {
		return userDao.updateUser(user);
	}

}
